<template>
  <a-modal
    :title="$t('发送短信')"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    class="customHeight customHeightChild modal_title"
    v-drag
  >
    <template slot="footer">
      <a-button @click="handleCancel" :loading="confirmLoading">{{ $t('取消') }}</a-button>
      <a-button type="primary" @click="handleOk" :loading="confirmLoading">{{ $t('发送') }}</a-button>
    </template>
    <a-row>
      <a-col :span="24" style="margin-bottom: 20px">
        <div style="margin-bottom: 10px; font-weight: 600; color: rgba(0, 0, 0, 0.8)">{{ $t('会员') }}</div>
        <a-table
          row-key="memberId"
          :columns="columns"
          :dataSource="dataSource"
          :scroll="{ y: 380 }"
          :pagination="false"
          bordered
          style="border: 1px solid #e5e5e5"
          class="customTable"
        ></a-table>
      </a-col>
      <a-col :span="24">
        <div style="margin-bottom: 10px; font-weight: 600; color: rgba(0, 0, 0, 0.8)">{{ $t('短信内容') }}</div>
        <a-textarea row="5" v-model="content" :placeholder="$t('请输入短信内容')"></a-textarea>
      </a-col>
    </a-row>
  </a-modal>
</template>
<script>
import { postAction } from '@/api/manage'
let that
export default {
  name: 'SendSmsModal',
  data() {
    return {
      width: 600,
      visible: false,
      confirmLoading: false,
      columns: [
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'phone',
          width: 150,
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'memberCardNo',
          width: 130,
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'name',
          width: 150,
        },
        {
          title: this.$t('币值'),
          align: 'right',
          dataIndex: 'totalCoin',
        },
      ],
      dataSource: [],
      content:''
    }
  },
  created() {
    that = this
  },
  methods: {
    edit(list) {
      that.dataSource = list
      that.content=''
      that.confirmLoading = false
      that.visible = true
    },
    handleCancel() {
      that.visible = false
    },
    handleOk() {
      let param = {}
      if(!that.content){
        that.$message.warning(that.$t('请输入短信内容'))
        return
      }
      param.memberId = that.dataSource.map(d=>{return d.memberId}).join(',')
      param.content = that.content
      that.confirmLoading = true
      postAction('/system/bisSmsRecord/sendByMember', param)
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.handleCancel()
            that.$emit('ok')
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
  },
}
</script>